package edu.kit.ksri.db.mturk.connectionhandlers;

import edu.kit.ksri.db.mturk.var.ConnectionMode;
import edu.kit.ksri.db.mturk.var.StaticInformation;

/**
 * Copyright (c) 2010-2011 Karlsruhe Institute of Technology (KIT), Germany
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 * 
 * --------------------------------------------------------------------------
 * 
 * Software: CSP/WMV tool for dynamic quality management of microtasks
 * http://www.ksri.kit.edu/Upload/Users/PeopleClouds/HCOMP2011_An_extendable_toolkit_for_managing_quality_of_human-based_eServices.pdf
 * 
 * Organization: Karlsruhe Institute of Technology (KIT), Germany
 * http://www.kit.edu
 * 
 * Project: PeopleClouds project of the Karlsruhe Service Research Institute(KSRI)
 * http://www.ksri.kit.edu/Default.aspx?PageId=818
 * 
 * Contributing authors: David Bermbach, Sandra Rath, Pascal Wichmann, Robert Kern
 */
public abstract class AbstractWorkerManager {

	/** AbstractWorkerManager Singleton */
	private static AbstractWorkerManager instance = null;

	/**
	 * 
	 * @return the {@link AbstractWorkerManager} singleton
	 */
	public static AbstractWorkerManager getInstance() {
		if (instance == null) {
			if (StaticInformation.scenario.getConnectionMode() == ConnectionMode.PERFSIM) {
				instance = new PerfSimWorkerManager();
			} 
			else if (StaticInformation.scenario.getConnectionMode() == ConnectionMode.CORRSIM) {
				instance = new CorrSimWorkerManager();
			}
			else if (StaticInformation.scenario.getConnectionMode() == ConnectionMode.SIM) {
				instance = new SimWorkerManager();
			}
			else
				instance = new WorkerManager();
		}
		return instance;
	}

	/**
	 * updates the qualification value for a worker. requires that the specific
	 * worker already has that qualification assigned.
	 * 
	 * @see StaticInformation
	 * 
	 * @param qualificationTypeId
	 *            the qualification which shall be updated
	 * @param workerId
	 *            the worker
	 * @param qualificationValue
	 *            the new qualifaction valeu
	 * @return true if successful
	 */
	public abstract boolean setQualificationValue(String qualificationTypeId,
			String workerId, int qualificationValue);

	/**
	 * assigns a qualification to an already known worker.
	 * 
	 * @param qualificationTypeId
	 *            the qualification which shall be assigned
	 * @param workerId
	 *            the worker
	 * @param qualificationValue
	 *            the initial value for the specific qualification
	 * @return true if the request was successful
	 */
	public abstract boolean assignQualification(String qualificationTypeId,
			String workerId, int qualificationValue);

	/**
	 * retrieves the current qualification value for the specified worker.
	 * 
	 * @param workerid
	 * @return the qualification value or null if the qualification does not
	 *         exist.
	 */
	public abstract Integer getQualificationValue(String workerid);

}
